/**
 * 
 */
package com.gragra.evaluateFunctionWords;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import com.gragra.parseOptions.CommandLineException;
import com.gragra.parseOptions.Parser;
/**
 * @author Christoph Teichmann
 * created Apr 28, 2013 9:52:12 PM
 * @version 0.1
 */
public class EvaluateFrequency
{
	/**
	 *
	 * @param args
	 * @throws CommandLineException 
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException
	{
		Parser pr = new Parser();
		EvaluateFunctionsWithMapping efm = new EvaluateFreqFunctionsWithMapping();
		try
		{efm.addOptions(pr);}
		catch(CommandLineException e)
		{
			System.out.println("initialization error:");
			e.printStackTrace();
			System.exit(-1);
		}
		pr.setProgramDescription("This program is used to evaluate function word detection based purely on frequency");
		pr.setMinArgs(2);
		pr.setMaxArgs(2);
		pr.setArgumentDescription(0, "The name of the input file that will be used.");
		pr.setArgumentDescription(1, "The name of the output file to which results will be written.");
		try
		{pr.parse(args);}
		catch(CommandLineException e)
		{
			e.printStackTrace();
			System.out.println(pr.writeOutHelp());
			System.exit(-1);
		}
		if(pr.hadHelp())
		{
			System.out.println(pr.writeOutHelp());
			System.exit(0);
		}
		BufferedReader br = new BufferedReader(pr.getFileReaderFromArgument(0));
		double[] res = efm.evaluate(pr, br);
		BufferedWriter bw = new BufferedWriter(pr.getFileWriterFromArgument(1));
		bw.write("Precision is: ");bw.write(Double.toString(res[0]));
		bw.newLine();
		bw.write("Recall is: ");bw.write(Double.toString(res[1]));
		bw.newLine();
		bw.write("F-Score is: ");bw.write(Double.toString(res[2]));
		br.close();
		bw.close();
	}
}